
def greet_user():
    print("Hello!")

greet_user()

def greet_user(username):
    print(f"Hello, {username.title()}!")

greet_user('jesse')


#练习8.work_1
def display_message():
    print('不愿再笑bro')

display_message()

#练习8.2
def favorite_book(title):
    print(f"One of my favorite books is {title}")
favorite_book("Antusheng")

def describe_pet(animal_type, pet_name):
    print(f"\nI have a {animal_type}.")
    print(f"My {animal_type}'s name is {pet_name.title()}.")
describe_pet('harry', 'hamster')
describe_pet('dog', 'willie')
describe_pet(animal_type='pig', pet_name='dd')

def pet(pet_name, animal_type='dog'):
    print(f"\nI have a {animal_type}.")
    print(f"My {animal_type}'s name is {pet_name.title()}.")
pet('willie')
pet(pet_name='willie')
pet(pet_name='harry', animal_type='hamster')

#练习8.3
def make_shirt(chima,ziyang):
    print(f"\n尺码是{chima},字样为{ziyang}")
make_shirt('xl','happy everyday')
make_shirt(chima='xs',ziyang='new')

#练习8.4
def make_shirt(chima,ziyang='I love Python'):
    print(f"\n尺码是{chima},字样为{ziyang}")
make_shirt('大号')
make_shirt(chima='中号')
make_shirt("ll",'SUN')

#练习8.5
def describe_city(city,country='China'):
    print(f"{city} is in {country}")

describe_city('dalian')
describe_city('Shanghai')
describe_city(city='Tokyo',country='Japan')

#8.3
'''
def get_formatted_name(first_name, last_name):
    full_name = f"{first_name} {last_name}"
    return full_name.title()

musician = get_formatted_name('jimi', 'hendrix')
print(musician)

print(get_formatted_name('a', 'b'))
'''

def get_formatted_name(first_name, last_name, middle_name=''):
    if middle_name:
        full_name = f"{first_name} {middle_name} {last_name}"
    else:
        full_name = f"{first_name} {last_name}"
    return full_name.title()

musician = get_formatted_name('jimi', 'hendrix')
print(musician)

musician_1 = get_formatted_name('john', 'hooker', 'lee')
print(musician_1)

'''
def build_person(first_name, last_name):
    person = {'first': first_name, 'last': last_name}
    return person

people=build_person('zhang','ming')
print(people)
'''

def build_person(first_name, last_name,age=None):
    person = {'first': first_name, 'last': last_name}
    if age:
        person['age'] = age

    return person

people=build_person('zhang','ming',50)
print(people)


'''
def get_formatted_name(first_name, last_name):
    full_name = f"{first_name} {last_name}"
    return full_name.title()

while True:
    print("your name is: ")
    f_name = input("First name: ")
    l_name = input("Last name: ")
    
    formatted_name = get_formatted_name(f_name, l_name)
    print(f"\nHello, {formatted_name}!")
    
    
def get_formatted_name(first_name, last_name):
    full_name = f"{first_name} {last_name}"
    return full_name.title()


while True:
    print("\nyour name:")
    print("(enter 'q' to quit)")

    f_name = input("First name: ")
    if f_name == 'q':
        break

    l_name = input("Last name: ")
    if l_name == 'q':
        break

    formatted_name = get_formatted_name(f_name, l_name)
    print(f"\nHello, {formatted_name}!")

'''

#练习8.6
def city_country(city,country):
    abc=f'{city},{country}'
    return abc
aa=city_country('dalian','china')
print(aa)

#练习8.7
'''
def make_album(singer,cd):
    result={'singer':singer,'cd':cd}
    return result
a_1=make_album('zhoujielun','daoxiang')
print(a_1)


def make_album(singer,cd,numbers=None):
    if numbers:
        result={'singer':singer,'cd':cd,'numbers':numbers}
    else:
        result={'singer':singer,'cd':cd}
    return result
a_1=make_album('zhoujielun','daoxiang',15)
print(a_1)
'''

#练习8.8
'''
def make_album(singer,cd):
    result={'singer':singer,'cd':cd}
    return result

while True:
    print("输⼊歌⼿名和专辑名\n按q退出")
    geshou=input('singer name: ')
    if geshou == 'q':
        break
    zhuanji=input('cd name: ')
    if zhuanji == 'q':
        break

    nname=make_album(geshou,zhuanji)
    print(nname)
'''
'''
def make_album(singer,cd):
    result={'singer':singer,'cd':cd}
    return result

active = True
while active:
    print("输⼊歌⼿名和专辑名\n按q退出")
    geshou = input('singer name: ')
    if geshou == 'q':
        active = False
        continue

    zhuanji = input('cd name: ')
    if zhuanji == 'q':
        active = False
        continue
        
    nname = make_album(geshou, zhuanji)
    print(nname)
'''
'''
def greet_users(names):
   for name in names:
        msg = f"Hello, {name.title()}!"
        print(msg)
usernames = ['hannah', 'ty', 'margot']
greet_users(usernames)
'''
'''
unprinted_designs = ['phone case', 'robot pendant', 'dodecahedron']
completed_models = []

while unprinted_designs:
    current_design = unprinted_designs.pop()
    print(f"Printing model: {current_design}")
    completed_models.append(current_design)
    
for i in completed_models: 
    print(i)
'''
'''
def print_models(unprinted_designs, completed_models):
    while unprinted_designs:
        current=unprinted_designs.pop()
        print('printing:',current)
        completed_models.append(current)

def show_completed_models(completed_models):
    print("\nThe following models have been printed:")
    for completed_model in completed_models:
        print(completed_model)

unprinted_designs = ['phone case', 'robot pendant', 'dodecahedron']
completed_models = []

print_models(unprinted_designs, completed_models)
show_completed_models(completed_models)
'''

'''8.9
text_unprinted=['aaa','bbb','ccc']
def show_messages(names):
    for i in names:
        print(i)

show_messages(text_unprinted)
'''
#练习8.10
'''
def send_messages(unprinted,over):
    while unprinted:
        result=unprinted.pop()
        print(result)
        over.append(result)
    print(over)

text_unprinted=['aaa','bbb','ccc']
text_over=[]
send_messages(text_unprinted,text_over)
'''

#练习8.11
def send_messages(unprinted,over):
    while unprinted:
        result=unprinted.pop()
        print(result)
        over.append(result)
    print(over)

text_unprinted=['aaa','bbb','ccc']
text_over=[]
send_messages(text_unprinted[:],text_over)
print(text_unprinted)

#8.5
'''
def make_pizza(*toppings):

    print(toppings)
make_pizza('pepperoni')
make_pizza('mushrooms', 'green peppers', 'extra cheese')
'''
'''
def make_pizza(*toppings):
    print("\nMaking a pizza with the following toppings:")
    for topping in toppings:
        print(f"- {topping}")

make_pizza('pepperoni')
make_pizza('mushrooms', 'green peppers', 'extra cheese')

def make_pizza_1(size, *toppings):
    print(f"\nMaking a {size}-inch pizza with the following toppings:")
    for topping in toppings:
        print(f"- {topping}") 
make_pizza_1(16, 'pepperoni')
make_pizza_1(12, 'mushrooms', 'green peppers', 'extra cheese')
'''
#练习8.12
'''
def sandwich(*items):
    print("\nMaking a sandwich with the following items:")
    for i in items:
        print(f"-{i}")

sandwich('ham', 'cheese', 'lettuce', 'tomato')
sandwich('turkey', 'mayo', 'mustard')
sandwich('apple')
'''
#练习8.13
'''
def build_profile(first, last, **user_info):
    user_info['first_name'] = first
    user_info['last_name'] = last
    return user_info
user_profile = build_profile('albert', 'einstein',
                               location='princeton',
                               field='physics')
print(user_profile)

'''
'''
def build_profile(first, last, **user_info):
    user_info['first_name'] = first
    user_info['last_name'] = last
    return user_info
me = build_profile('liu', 'chang',
                   location='dalian',
                   field='mathmatics',
                   hobby='food',
                   friend='jin')
print(me)

'''
#8.14
def make_car(make, model, **other):
    other['make']=make
    other['model']=model
    return other

car = make_car('subaru', 'outback', color='blue',
               tow_package=True)
print(car)

import p8_1
p8_1.make_pizza('大','LEG','pepperoni')
p8_1.make_pizza(12, 'mushrooms', 'green peppers', 'extra cheese')
